﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<link rel="stylesheet" type="text/css" href="lib/My97DatePicker/4.8/skin/WdatePicker.css"></head>
<link rel="stylesheet" href="lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title></title>
</head>
<body>

<div style="">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe64b;</i> 积分管理 <span id="officeNameSpan"> </span> <span class="c-gray en">&gt;</span> 积分商品 </nav>
	<div class="page-container">
		<!-- <div class="text-c"> 日期范围：
			<input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
			-
			<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
			<input type="text" class="input-text" style="width:250px" placeholder="输入会员名称、电话、邮箱" id="" name="">
			<button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
		</div> -->
		<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
			<a href="javascript:;" onclick="batchdel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a href="javascript:;" onclick="add('添加用户','','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加商品</a></span> 
			<span class="r">共有数据：<strong id="count"></strong> 条</span> </div>
		<div class="mt-20">
		<input type="hidden" id="tId" name="tId" value="">
		<input type="hidden" id="tempName" name="officeName" value="">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="15%">名称</th>
					<th width="30%">描述</th>
					<th width="10%">价格</th>
					<th width="10%">积分</th>
					<th width="15%">缩略图</th>
					<th width="">操作</th>
				</tr>
			</thead>
			<tbody id="data">
				
			</tbody>
		</table>
		</div>
	</div>
</div>
<div id="infoDiv" class="bringins-content" style="display:none;">
	<form action="" method="post" class="form form-horizontal" id="form-category-add" novalidate="novalidate">
		<div id="tab-category" class="HuiTab">
			<div class="tabBar cl">
				<span class="current">基本信息</span>
			</div>
			<div class="tabCon" style="display: block;">
				<input class="goods" type="hidden" id="id" name="id" value="">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text goods" value="" placeholder="" id="name" name="name">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>描述：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="textarea goods" value="" placeholder="" id="description" name="description">
					</div>
				</div>
				<!-- <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>类型：</label>
					<div class="formControls col-xs-8 col-sm-9" id="">
						<span class="select-box text_width30">
						  <select class="select goods" size="1" name="tempId" id="tempId">
						  </select>
						</span>
					</div>
				</div> -->
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>价格：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text goods" value="" placeholder="" id="price" name="price">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>积分：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text goods" value="" placeholder="" id="score" name="score">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>图片：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="hidden" class="input-text goods" value="" id="fileId" name="fileId">
						<span class="btn-upload">
							<a href="javascript:void();" class="btn btn-primary radius">选择文件
								<span class="red" style="font-size:11px;">(默认不修改)</span></a>
							<input type="file" id="file" name="file" multiple name="file_0" class="input-file">
						</span>
						<br>
						<img id="fileShow" style="display:none;padding-top:5px;" class="thumb_img100 goods " alt="" src="">
					</div>
				</div>
				<div class="row cl">
					<span class="">&nbsp;&nbsp;&nbsp;&nbsp;</span>
					<span class="">类型补充属性</span>
					<div class="line" style="border-top: solid 2px #fff;"></div>
				</div>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input class="btn btn-primary radius" id="submit" type="button" onclick="save()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="static/h-ui.admin/js/common.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/utils.js"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/bringins/js/bringins.js"></script>
<script type="text/javascript" src="lib/plupload/plupload.full.min.js"></script>
<script type="text/javascript">
$(function(){
	loadGoodsData();
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#tab-category").Huitab({
		index:0
	});
});

//根据类型id获取对应的商品列表
function loadGoodsData(){
	var url = "/scoreGoods/list?pageNum=-1";
	common.getData(url,function(data){
		cleanDataTable();
		var list = data.result;
		var html="";
		for(var i=0;i<list.length;i++){
			var obj = list[i];
			html+='<tr class="text-c">\
				<td><input type="checkbox" value="'+obj.id+'" name="id"></td>\
				<td>'+obj.name+'</td>\
				<td>'+obj.description+'</td>\
				<td>'+obj.price+'</td>\
				<td>'+obj.score+'</td>\
				<td><img class="thumb_img60" alt="'+obj.name+'" src="'+obj.extraData.imgPath+'"></td>\
				<td class="td-manage">\
				<a title="编辑" href="javascript:;" onclick="edit(\'编辑\',\''+obj.id+'\')" class="ml-5" style="text-decoration:none">\
				<i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="del(\''+obj.id+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>\
			</tr>';
		}
		$("#data").html(html);
		$("#count").html(data.result.total);
		if(list.length>0){
			sortDataTable();
		}
	});
}
function sortDataTable(){
	$('.table-sort').dataTable({
		"aaSorting": [[ 3, "desc" ]],//默认第几个排序
		"bStateSave": true,//状态保存
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,5]}// 制定列不参与排序
		]
	});
}
//清除旧数据
function cleanDataTable(){
	if ($('.table-sort').hasClass('dataTable')) {
		var dttable = $('.table-sort').dataTable();
		dttable.fnClearTable(); //清空一下table
		dttable.fnDestroy(); //还原初始化了的datatable
	}
}

/*添加*/
function add(title,url,w,h){
	common.addParams({func:"add"});
	//layer_show(title,url,w,h);
	$('#infoDiv').bringins({
		"position":"right",
		"color":"#e5e5e5",
		"width":"60%",
		"closeButton":"white"
	});
	$("#id").val("");
	loadDataInfo();
}
function loadDataInfo(){
	//清除旧数据
	$(".goods").val("");
	$(".fieldsetDiv").remove();
	$("#file").attr("src","");
	
	var params = common.getParams();
	$("#id").val(params.id?params.id:"");
	$("#submit").attr("attr1",params.func);

	loadGoodsType();		//加载商品类型
}

//保存数据
function save(){
	var name = $("#name").val();
	var description = $("#description").val();
	var score = $("#score").val();
	var price = $("#price").val();
	//var tempId = $("#tempId").val();
	var imgId = $("#fileId").val();
	
	var fieldset = {};
	$('div[name="fieldsets"]').each(function(i,e){ 
		var div = $(e);
		var key = div.find("label[name='key']").html();
		var val = div.find("input[name='val']").val();
		fieldset[key]=val;
	}); 
	
	var attr1 = $("#submit").attr("attr1");
	if(attr1=="add"){
		var url = "/scoreGoods/create";
		var data={name:name,score:score,price:price,description:description,imgId:imgId,fieldset:JSON.stringify(fieldset)};
	}else{
		var url = "/scoreGoods/update";
		var id = $("#id").val();
		var data={id:id,name:name,score:score,price:price,description:description,imgId:imgId,fieldset:JSON.stringify(fieldset)};
	}
	common.postData(url,data,function(data){
		window.location.reload();
		common.alertX(data.msg);
		parent.layer.close(parent.layer.getFrameIndex(window.name));
	});
}
//编辑
function edit(title,id){
	common.addParams({id:id,func:"edit"});
	//layer_show(title,url,w,h);
	$('#infoDiv').bringins({
		"position":"right",
		"color":"#e5e5e5",
		"width":"60%",
		"closeButton":"white"
	});
	loadDataInfo();
}
//加载商品详情
function loadGoodsInfo(){
	var id = $("#id").val();
	if(!id){
		return;
	}
	
	var url = "/scoreGoods/getInfoById?id="+id;
	common.getData(url,function(data){
	
		var obj = data.result;
		$("#name").val(obj.name);
		$("#description").val(obj.description);
		$("#price").val(obj.price);
		$("#score").val(obj.score);
		
		$("#tempId").val(obj.tempId);
		
		//var fieldsetJson = $.parseJSON(obj.fieldset);
		var fieldsetJson = obj.extraData;
		var html = "";
		$(".fieldsetDiv").remove();
		for(var p in fieldsetJson){
			//alert("key:"+p+" ->val:"+fieldsetJson[p]);
			html+='<div class="row cl fieldsetDiv" name="fieldsets">\
				<label class="form-label col-xs-4 col-sm-3" name="key">'+p+'</label>\
				<div class="formControls col-xs-8 col-sm-9">\
					<input type="text" class="input-text" value="'+fieldsetJson[p]+'" placeholder="" id="" name="val">\
				</div>\
			</div>';
		}
		$("#tab-category").after(html);
	});
}

/*删除*/
function del(id){
	layer.confirm('确认要删除吗？',function(index){
		var data={id:id};
		var url = "/scoreGoods/del";
		common.postData(url,data,function(data){
			window.location.reload();
			layer.msg(data.msg,{icon:1,time:1000});
		});
	});
}
/*批量删除*/
function batchdel(){
	var ids = [];
	$('input[name="id"]:checked').each(function(i,e){ 
		<!-- ids[i]=$(e).val(); -->
		ids.push($(e).val());
	}); 
	
	if(ids.length>0){
		layer.confirm('确认要批量删除吗？',function(index){
			var data={ids:ids};
			var url = "/goods/batchDel";
			common.postData(url,data,function(data){
				window.location.reload();
				layer.msg(data.msg,{icon:1,time:1000});
			});
			
		});
	}else{
		common.alertX("请选择要删除的数据.");
	}
}
//绑定图片到对应的商品(逻辑变动，所以暂留)
function bindGoodsId(id,goodsId){
	if(!id || !goodsId){
		return;
	}
	var url = "/goodsImg/bindGoodsId";
	var data={id:id,goodsId:goodsId};
	common.postData(url,data,function(data){
		common.msg(data.msg);
	});
	
}

//上传图片
//实例化一个plupload上传对象
var uploader = new plupload.Uploader({
	browse_button : 'file', //触发文件选择对话框的按钮，为那个元素id
	url : common.basePath+'/goodsImg/create', //服务器端的上传页面地址
	flash_swf_url : 'js/Moxie.swf', //swf文件，当需要使用swf方式进行上传时需要配置该参数
	silverlight_xap_url : 'js/Moxie.xap' //silverlight文件，当需要使用silverlight方式进行上传时需要配置该参数
});    
uploader.bind('FilesAdded',function(uploader,files){
	uploader.start(); 
});

uploader.bind('FileUploaded',function(uploader,files,responseObject){
	var res = $.parseJSON(responseObject.response);
	var id = res.result.id;
	$("#fileShow").show();
	$("#fileShow").attr('src',res.result.extraData.imgPath); 
	$("#fileId").val(res.result.id);
	//bindGoodsId(id,goodsId);
});
//在实例对象上调用init()方法进行初始化
uploader.init();



</script> 
</body>
</html>